package com.example.jh352160.surfingtv.category.customView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.jh352160.surfingtv.R;
import com.example.jh352160.surfingtv.thematic_details.ThematicDetailsPage;

/**
 * Created by jh352160 on 2016/7/25
 */

public class Subscribe_item extends LinearLayout {

    private Context context;
    ImageView image;
    TextView title;
    TextView about;

    //detail page data
    String titleText;
    String detailUrl;
    int favoriteCount;
    boolean isfavorite;
    int contentId;

    public Subscribe_item(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public Subscribe_item(Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.category_subscribe_item, this);
        image = (ImageView) findViewById(R.id.image);
        title = (TextView) findViewById(R.id.title);
        about = (TextView) findViewById(R.id.about);
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ThematicDetailsPage.class);
                intent.putExtra("detailUrl", detailUrl);
                intent.putExtra("title", titleText);
                intent.putExtra("favoriteCount", favoriteCount);
                intent.putExtra("isfavorite", isfavorite);
                intent.putExtra("contentId", contentId);
                context.startActivity(intent);
            }
        });
    }

    public void setText(String titleText, String aboutText) {
        this.titleText = titleText;
        title.setText(titleText);
        about.setText(aboutText);
    }

    public void setData(String titleText, String aboutText, String imageUrl, String detailUrl, int favoriteCount, boolean isfavorite, int contentId) {
        title.setText(titleText);
        about.setText(aboutText);
        Glide.with(context).load(imageUrl).into(image);
        this.detailUrl = detailUrl;
        this.favoriteCount = favoriteCount;
        this.isfavorite = isfavorite;
        this.titleText = titleText;
        this.contentId = contentId;
    }
}
